package com.yuanfeng.base.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanfeng.base.dto.BaseArticleGroupDTO;
import com.yuanfeng.base.entity.BaseArticleGroupEntity;
import com.yuanfeng.base.mapper.BaseArticleGroupMapper;
import com.yuanfeng.base.service.BaseArticleGroupService;
import com.yuanfeng.base.vo.index.WebIndexArticleGroupVO;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.ParseTokenUtils;
import com.yuanfeng.commoms.util.ResponseResult;
import com.yuanfeng.commoms.vo.user.UserInfoVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName BaseArticleGroupServiceImpl
 * @Description 网站初始化内容分组表
 * @Author cyp
 * @Date 2023-06-07 14:50:02
 * @Version 1.0
 **/
@Service
public class BaseArticleGroupServiceImpl extends ServiceImpl<BaseArticleGroupMapper, BaseArticleGroupEntity>
        implements BaseArticleGroupService {

    @Override
    public ResponseResult queryArticleGroup() {
        // 查询所有的组
        List<WebIndexArticleGroupVO> articleGroups = this.baseMapper.selectAllGroup();

        return ResponseResult.success(articleGroups);
    }

    @Override
    public ResponseResult updateArticleGroup(BaseArticleGroupDTO baseArticleGroupReq) {
        UserInfoVO userInfo = ParseTokenUtils.getPlatformUser(baseArticleGroupReq.getToken());
        if (null != userInfo) {
            this.baseMapper.insertArticleGroup(baseArticleGroupReq);
            return ResponseResult.success(BizCodeEnume.OPERATION_SUCCESSFUL);
        }
        return ResponseResult.fail(BizCodeEnume.TOKEN_IS_ILLEGAL);
    }

    @Override
    public ResponseResult deleteArticleGroup(BaseArticleGroupDTO baseArticleGroupReq) {
        UserInfoVO userInfo = ParseTokenUtils.getPlatformUser(baseArticleGroupReq.getToken());
        if (null != userInfo) {
            this.baseMapper.deleteById(baseArticleGroupReq.getArticleGroupId());
            return ResponseResult.success();
        }
        return ResponseResult.fail(BizCodeEnume.TOKEN_IS_ILLEGAL);
    }
}
